package com.mvc4g.example.mockup.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mvc4g.example.mockup.client.MockUpService;
import com.mvc4g.example.mockup.client.bean.AboutBean;
import com.mvc4g.example.mockup.client.bean.EmailBean;
import com.mvc4g.example.mockup.client.bean.LoginBean;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class MockUpServiceImpl extends RemoteServiceServlet implements
		MockUpService {

	private List<EmailBean> emailList = new ArrayList<EmailBean>();
	private Map<Integer, String> emailContent = new HashMap<Integer, String>();

	public MockUpServiceImpl(){
		EmailBean email = null;
		for(int i=0; i<10; i++){
			email = new EmailBean();
			email.setId(i);
			email.setSubject("Subject " + i);
			emailList.add(email);
			emailContent.put(i, "Content " + i);
		}
	}
	
	public void login(LoginBean login) {
		// Nothing to do, login always ok
	}

	public List<EmailBean> getEmails(String login) {
		return emailList;
	}
	
	public String getContent(int id){
		return emailContent.get(id);
	}
	
	public AboutBean getAbout(){
		AboutBean aboutBean = new AboutBean();
		aboutBean.setTitle("About Widget Title");
		aboutBean.setBody("About Widget Body");
		aboutBean.setIntroduction("Introduction");
		return aboutBean;		
	}
}
